package com.zrrd.service.impl;

import com.zrrd.mapper.TeaMapper;
import com.zrrd.pojo.Tea;
import com.zrrd.service.TeaService;
import com.zrrd.utils.DBUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title TeaServiceImpl
 * @description
 * @create 2024/1/24 11:38
 */
public class TeaServiceImpl implements TeaService {
    private SqlSessionFactory sessionFactory;
    {
        sessionFactory = DBUtils.getSessionFactory();
    }
    /**
     * 查询所有
     *
     * @return
     */
    @Override
    public List<Tea> queryTeaAll() {
        SqlSession sqlSession = sessionFactory.openSession();
        TeaMapper mapper = sqlSession.getMapper(TeaMapper.class);
        List<Tea> teas = mapper.queryTeaAll();
        sqlSession.close();
        return teas;
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public Tea queryOneById(Integer id) {
        return null;
    }

    /**
     * 插入
     *
     * @param tea
     * @return
     */
    @Override
    public Integer addTea(Tea tea) {
        SqlSession sqlSession = sessionFactory.openSession(true);
        TeaMapper mapper = sqlSession.getMapper(TeaMapper.class);
        Integer count = mapper.insertTea(tea);
        sqlSession.close();
        return count;
    }

    /**
     * 修改
     *
     * @param tea
     * @return
     */
    @Override
    public Integer updateTea(Tea tea) {
        return null;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public Integer removeTea(Integer id) {
        SqlSession sqlSession = sessionFactory.openSession(true);
        TeaMapper mapper = sqlSession.getMapper(TeaMapper.class);
        Integer count = mapper.deleteTea(id);
        sqlSession.close();
        return count;
    }

    /**
     * 根据条件查询
     *
     * @param tea
     * @return
     */
    @Override
    public List<Tea> queryByCondition(Tea tea) {
        return null;
    }

    /**
     * 根据多个id查询
     *
     * @param ids
     * @return
     */
    @Override
    public List<Tea> queryByIds(List<Integer> ids) {
        return null;
    }
}
